import React, { Suspense, lazy } from 'react'

import Login from "../modules/login/Login"
import Layout from "../modules/layout/index"





const routes = [
    {
        path: "/",
        component: Login,
        exact:true, // 强匹配
        layout: false,
    },

    {
        path: "/layout",
        component: Layout,
        redirect: "/layout",
        exact: true,
    },

]



// 实现react-router-config里的renderRoutes方法
function renderRoutes (routes:any, extraProps = {}, switchProps = {}) {
    return routes ? (
        <Suspense fallback={<div>页面加载中...</div>}>
            <Switch {...switchProps}>
                {routes.map((route, i) => (
                    <Route
                        key={route.key || i}
                        path={route.path}
                        exact={route.exact}
                        strict={route.strict}
                        render={props =>
                            route.render ? (
                                route.render({ ...props, ...extraProps, route: route })
                            ) : (
                                <route.component {...props} {...extraProps} route={route} />
                            )
                        }
                    />
                ))}
            </Switch>
        </Suspense>
    ) : null;
}

// 实现react-router-config里的matchRoutes方法
function matchRoutes (routes, pathname, /*not public API*/ branch = []) {
    routes.some(route => {
        const match = route.path
            ? matchPath(pathname, route)
            : branch.length
                ? branch[branch.length - 1].match // use parent match
                : Router.computeRootMatch(pathname); // use default "root" match
        
                if (match) {
            branch.push({ route, match });

            if (route.routes) {
                matchRoutes(route.routes, pathname, branch);
            }
        }
        return match;
    });
    return branch;
}


export default routes